$(window).resize(function () {
    if (appVM) {
        appVM.windowHeight = $(window).height();
    }
});

const app = Vue.createApp(joEl.buildVueAppParam({
    data: function () {
        return {
            windowHeight: $(window).height(),
            // defaultHeight: $(window).height() - 160,
            // tableHeight: $(window).height() - 80,
            id: jo.getUrlParam('id'),
            // 表单详情
            formData: {
                extInfo: {}
                , fieldList: []
            },
            // 字段集合
            // columnList: [],
            // 当前选中字段
            curCol: null,

            // 格式集合
            showFormatList: [],
            // 查询条件类型
            asConditionTypeList: [],
            // 控件类型
            controlTypeList: [],
            // 控件表单校验规则
            controlCheckList: [],

            // 按钮表单
            btnFormDialog: false,
            // 按钮表单类型, 1:按钮栏, 2:行级按钮
            btnFormType: 1,
            // 按钮表单实际数据
            btnFormData: {},
            // 按钮表单展示数据
            btnFormShowData: {},

            // 查询条件选择表单展示
            searchConditionListForm: false,
            // 查询条件选中项
            searchConditionChecked: [],
            // 被拖拽数据
            dragData: null,


        };
    }
    , computed: {
        defaultHeight() {
            return this.windowHeight - 160;
        },
        tableHeight() {
            return this.windowHeight - 80;
        },
        contentHeight() {
            return this.windowHeight - 85;
        },
        allWidthIs24() {
            var flag = true;
            jo.forEach(this.columnList, function (item) {
                if (item.formColumnGridWidth != 24) {
                    flag = false;
                }
            });
            return flag;
        },
        allWidthIs12() {
            var flag = true;
            jo.forEach(this.columnList, function (item) {
                if (item.formColumnGridWidth != 12) {
                    flag = false;
                }
            });
            return flag;
        },
        allWidthIs8() {
            var flag = true;
            jo.forEach(this.columnList, function (item) {
                if (item.formColumnGridWidth != 8) {
                    flag = false;
                }
            });
            return flag;
        },
        // 字段列集合
        columnList() {
            if (this.formData) {
                return this.formData.fieldList;
            }
            return [];
        },
        // 校验规则map格式
        controlCheckMap() {
            return jo.array2Object(this.controlCheckList, function (item) {
                return item.key;
            }, function (item) {
                return item.value;
            });
        },
        // 视图配置
        columnListForView() {
            var arr = [];
            jo.forEach(this.columnList, function (item, i) {
                arr.push(item);
            });
            // 排序
            jo.sort(arr, function (a, b) {
                var one = jo.getDefVal(a.listColumnOrder, 0) + (a.listColumnShow == 1 ? 0 : 900000000);
                var two = jo.getDefVal(b.listColumnOrder, 0) + (b.listColumnShow == 1 ? 0 : 900000000);
                return one < two;
            });
            return arr;
        },
        // 查询条件可选项
        columnListForViewCondition() {
            var arr = [];
            var map = jo.array2Object(this.formData.extInfo.searchConditionList, function (item) {
                return item.fieldJavaName;
            })
            jo.forEach(this.columnListForView, function (item, i) {
                if (item.listQueryCondition && item.listQueryCondition != 1) {
                    // 过滤掉已经选择了的
                    if (!map[item.fieldJavaName]) {
                        arr.push(item);
                    }
                }
            });
            return arr;
        },
        // 表单配置
        columnListForForm() {
            var arr = [];
            jo.forEach(this.columnList, function (item, i) {
                arr.push(item);
            });
            // 排序
            jo.sort(arr, function (a, b) {
                var one = jo.getDefVal(a.formColumnOrder, 0);
                var two = jo.getDefVal(b.formColumnOrder, 0);
                return one < two;
            });
            return arr;
        },
        // 拖拽版表单配置
        columnListForFormDrag() {
            var arr = [];
            jo.forEach(this.columnList, function (item, i) {
                arr.push(item);
                // 处理虚拟字段, 用于交互使用, 后端不存储
                if (item.formControlCheckRule && item.formControlCheckRule.checkRuleList) {
                    if (!item.v_checkRuleTypeList || item.v_checkRuleTypeList.length === 0) {
                        item.v_checkRuleTypeList = [];
                        // 只有第一次才push
                        jo.forEach(item.formControlCheckRule.checkRuleList, function (rule) {
                            item.v_checkRuleTypeList.push(rule.checkType);
                        });
                    }
                }
            });
            // 排序
            jo.sort(arr, function (a, b) {
                var one = jo.getDefVal(a.formColumnOrder, 0);
                var two = jo.getDefVal(b.formColumnOrder, 0);
                return one < two;
            });
            return arr;
        },
        // 判断是否显示控件数据源
        showOptionDataSource() {
            var controlType = this.curCol.formControlType;
            return controlType === 'select'
                || controlType === 'radio'
                || controlType === 'checkbox';
        }
    }
    , methods: {
        // 查询条件选择确认
        searchConditionConfirm() {
            var _this = this;
            if (this.searchConditionChecked && this.searchConditionChecked.length > 0) {
                if (!this.formData.extInfo.searchConditionList) {
                    this.formData.extInfo.searchConditionList = [];
                }
                var map = jo.array2Object(this.columnListForViewCondition, function (item) {
                    return item.fieldJavaName;
                });
                jo.forEach(this.searchConditionChecked, function (item) {
                    var field = map[item];
                    if (!field) {
                        console.warn('[查询条件选择确认] 根据字段名查找字段失败,字段名:', item, map)
                        return;
                    }
                    _this.formData.extInfo.searchConditionList.push({
                        fieldJavaName: item,
                        listHeaderTitle: field.listHeaderTitle,
                        listQueryCondition: field.listQueryCondition
                    });
                });

            }
            this.searchConditionListForm = false;
            // 清空选项
            this.searchConditionChecked = [];
        },
        // 新增列表页按钮
        addListBtn(type) {
            this.btnFormType = type;
            if (type === 1) {
                this.btnFormData = {size: 'default', type: 'primary', category: 'plain'};
                this.btnFormShowData = {size: 'default', type: 'primary', category: 'plain'};
            } else if (type === 2) {
                this.btnFormData = {size: 'default', type: 'primary', category: 'link'};
                this.btnFormShowData = {size: 'default', type: 'primary', category: 'link'};
            }
            this.btnFormDialog = true;
        },
        // 编辑按钮
        editListBtn(btn, type) {
            this.btnFormType = type;
            this.btnFormData = btn;
            this.btnFormShowData = jo.copyObjectDeep(btn);
            this.btnFormDialog = true;
        },
        // 删除按钮
        deleteListBtn(btn, type) {
            var _this = this;
            jo.confirm('您确定要删除按钮【' + btn.name + '】嘛?', function () {
                var arr = [];
                var list = [];
                if (type === 1) {
                    list = _this.formData.extInfo.buttonBarConfig.buttonList;
                } else if (type === 2) {
                    list = _this.formData.extInfo.tableRowButtonConfig.buttonList;
                }
                jo.forEach(list, function (item) {
                    if (item.code != btn.code) {
                        arr.push(item);
                    }
                });
                if (type === 1) {
                    _this.formData.extInfo.buttonBarConfig.buttonList = arr;
                } else if (type === 2) {
                    _this.formData.extInfo.tableRowButtonConfig.buttonList = arr;
                }
            });
        },
        // 保存按钮
        saveListBtn() {
            // 校验
            if (!this.btnFormShowData.name || !this.btnFormShowData.size) {
                jo.showErrorMsg('存在必填值为空');
                return;
            }
            // 区分新增和修改
            if (this.btnFormData.code) {
                // code有效是更新
                for (var k in this.btnFormShowData) {
                    var newVal = this.btnFormShowData[k];
                    var oldVal = this.btnFormData[k];
                    // 值前后有变化则更新
                    if (newVal != oldVal) {
                        this.btnFormData[k] = newVal;
                        console.debug('[保存按钮] 更新按钮属性,字段=%s,新值=%s,老值=%s', k, newVal, oldVal);
                    }
                }
            } else {
                // 新增
                if (!this.formData.extInfo.buttonBarConfig) {
                    this.formData.extInfo.buttonBarConfig = {};
                }
                if (!this.formData.extInfo.buttonBarConfig.buttonList) {
                    this.formData.extInfo.buttonBarConfig.buttonList = [];
                }
                if (!this.formData.extInfo.tableRowButtonConfig) {
                    this.formData.extInfo.tableRowButtonConfig = {};
                }
                if (!this.formData.extInfo.tableRowButtonConfig.buttonList) {
                    this.formData.extInfo.tableRowButtonConfig.buttonList = [];
                }
                // 新增时赋值默认code
                this.btnFormShowData.code = jo.getUUID(16);
                if (this.btnFormType === 1) {
                    this.formData.extInfo.buttonBarConfig.buttonList.push(this.btnFormShowData);
                } else if (this.btnFormType === 2) {
                    this.formData.extInfo.tableRowButtonConfig.buttonList.push(this.btnFormShowData);
                }
            }
            // 关闭前清掉数据
            this.btnFormData = {};
            this.btnFormShowData = {};
            this.btnFormType = 0;
            // 关闭
            this.btnFormDialog = false;
        },
        // 表格配置行样式{ row, rowIndex }
        tableConfigRowStyle(obj) {
            if (obj.row && obj.row.listColumnShow == 0) {
                return {backgroundColor: '#FAFAFA', textDecoration: 'line-through'};
            }
        },
        // 批量设置表单列数
        batchSetFormColumnWidth(span) {
            jo.forEach(this.formData.fieldList, function (item) {
                item.formColumnGridWidth = span;
            });
        },
        // 校验规则多选框变更
        checkRuleListChange(val) {
            this.curCol.v_checkRuleTypeList = val;
            // 原先的规则映射
            var oldRuleMap = {};
            jo.forEach(this.curCol.formControlCheckRule.checkRuleList, function (item) {
                oldRuleMap[item.checkType] = item;
            });

            // 新校验规则对象集合
            var arr = [];
            jo.forEach(this.curCol.v_checkRuleTypeList, function (item) {
                var old = oldRuleMap[item];
                if (old) {
                    arr.push(old);
                } else {
                    var check = {checkType: item, checkReg: '', errorTips: ''};
                    if (item === 'ErrMail') {
                        check.errorTips = '请输入正确的邮箱格式';
                    } else if (item === 'ErrPhone') {
                        check.errorTips = '请输入正确的手机号格式';
                    } else {
                        check.errorTips = '请输入符合要求的内容';
                    }
                    arr.push(check);
                }
            });
            this.curCol.formControlCheckRule.checkRuleList = arr;
        },
        // 获取规则名称
        getCheckRuleName(checkType) {
            var name = this.controlCheckMap[checkType];
            return name ? name : checkType;
        },
        // 删除数据项
        deleteOptionItem(idx) {
            var arr = [];
            jo.forEach(this.curCol.formControlDataSource.optionItemList, function (item, i) {
                if (idx === i) {
                    return;
                }
                arr.push(item);
            });
            this.curCol.formControlDataSource.optionItemList = arr;
        },
        // 添加数据项
        addOptionItem() {
            if (!this.curCol.formControlDataSource.optionItemList) {
                this.curCol.formControlDataSource.optionItemList = [];
            }
            this.curCol.formControlDataSource.optionItemList.push({key: '', value: ''});
        },
        // 拖拽结束后调整位置, 参数: 被拖拽对象, 锚定对象, 移动到锚定对象的后面after或者前面before
        dragPosition(target, posItem, type) {
            var num = 0;
            jo.forEach(this.columnListForForm, function (item, i) {
                item.formColumnOrder = (i + 1) * 10;
                // 找到锚定对象
                if ($(posItem).attr('dataColId') == item.fieldDbName) {
                    if (type === 'after') {
                        num = item.formColumnOrder + 5;
                    } else {
                        num = item.formColumnOrder - 5;
                    }
                }
            });
            if (num) {
                jo.forEach(this.columnList, function (item, i) {
                    // 找到锚定对象
                    if ($(target).attr('dataColId') == item.fieldDbName) {
                        item.formColumnOrder = num;
                    }
                });
            }
        },
        // 选中字段
        colDetail(col) {
            this.curCol = col;
        },
        // 表选择
        tableChange(val) {
            var _this = this;
            jo.postJson('{URL_CMS}lowcode/generate/initGenerateByTableName', {body: val}).success(function (json) {
                if (json && json.code == 0) {
                    _this.formData = json.data;
                    _this.curCol = null;
                }
            });
        },
        // 枚举数据初始化
        init() {
            var _this = this;
            if (this.id) {
                jo.postJsonAjax('{URL_CMS}lowcode/generate/getGenerateDetail', {body: this.id}).success(function (json) {
                    _this.formData = json.data;
                    if (!_this.formData.formPageConfig) {
                        _this.formData.formPageConfig = {};
                    }
                    _this.formPageConfig = _this.formData.formPageConfig;
                    if (!_this.formPageConfig.elementList) {
                        _this.formPageConfig.elementList = [];
                    }
                }).error(function (json) {
                    jo.showErrorMsg('查询详情失败');
                });
            }


            jo.postJsonAjax("{URL_CMS}lowcode/generate/getShowFormatList", {}).success(function (json) {
                _this.showFormatList = json.data;
            });
            jo.postJsonAjax("{URL_CMS}lowcode/generate/getQueryConditionTypeList", {}).success(function (json) {
                _this.asConditionTypeList = json.data;
            });
            jo.postJsonAjax("{URL_CMS}lowcode/generate/getControlTypeList", {}).success(function (json) {
                _this.controlTypeList = json.data;
            });
            jo.postJsonAjax("{URL_CMS}lowcode/generate/getControlCheckList", {}).success(function (json) {
                _this.controlCheckList = json.data;
            });
        },
        // 新增
        add() {
            jo.postJsonAjax('/lowcode/generate/addGenerateConfig', {body: this.formData}).success(function (json) {
                parent.jo.showSuccessMsg('保存成功~');
                // 刷新表格数据
                parent.appVM.list_refresh();
                // 关闭弹窗
                jo.closeSelf();
            }).error(function (json) {
                parent.jo.showErrorMsg('保存失败~');
            });
        },
        // 更新
        update() {
            jo.postJsonAjax('/lowcode/generate/update', {body: this.formData}).success(function (json) {
                parent.jo.showSuccessMsg('更新成功~');
                // 刷新表格数据
                parent.appVM.list_refresh();
                // 关闭弹窗
                jo.closeSelf();
            }).error(function (json) {
                parent.jo.showErrorMsg('更新失败~');
            });
        },
        // 同步字段变更
        syncFieldChange() {
            var _this = this;
            jo.postJsonAjax('/lowcode/generate/syncFieldChange', {body: this.id}).success(function (json) {
                parent.jo.showSuccessMsg('同步成功~');
                _this.formData = json.data;
                _this.curCol = null;
            }).error(function (json) {
                parent.jo.showErrorMsg('同步失败~');
            });
        },
        // 新增
        del(func) {
            jo.confirm('您确定要删除嘛?', function (idx) {
                jo.postJsonAjax('/lowcode/generate/delete', {body: this.id}).success(function (json) {
                    if (typeof func == 'function') {
                        func(json);
                    } else {
                        parent.jo.showSuccessMsg('删除成功~');
                        // 刷新表格数据
                        parent.appVM.list_refresh();
                        // 关闭弹窗
                        jo.closeSelf();
                    }
                }).error(function (json) {
                    parent.jo.showErrorMsg('删除失败~');
                });
                jo.close(idx);
            });

        },

        // 拖拽开始:被拖拽对象
        dragStart(e, item) {
            // 设置被拖拽按钮
            this.dragBtn = item;
        },
        // 拖拽中:被拖拽对象
        drag(e, item) {
        },
        // 拖拽结束:被拖拽对象
        dragEnd(e, item) {
            // 清空数据
            this.dragBtn = null;
            // 清空
            $('.btn-bar-item-left').removeClass('btn-bar-item-left');
            $('.btn-bar-item-right').removeClass('btn-bar-item-right');
        },
        // 拖拽进入:目标对象
        dragEnter(e, item) {
        },
        // 拖拽在目标对象上移动:目标对象
        dragOver(e, item) {
            e.preventDefault();
            this.dragOverCore(e, item, this.dragBtn, 'code');
        },
        // 拖拽离开:目标对象
        dragLeave(e, item) {
        },
        // 拖拽放置:目标对象
        drop(e, item, type) {
            if (!this.dragBtn) {
                console.warn('[按钮拖拽放置] 被拖拽按钮查找失败');
                return;
            }
            if (!item) {
                return;
            }
            // 被拖拽按钮配置
            var dragBtn = this.dragBtn;
            if (dragBtn.code == item.code) {
                console.log('[按钮拖拽放置] 被拖拽按钮与放置按钮疑似同一个,不做处理');
                return;
            }

            // 定位信息
            var position = jo.getPositionDetail(e, 'btn-bar-item')

            // 判断鼠标是否过了中线, 过了就放右边, 否则放左边
            var arr = [];
            var oldArr = [];
            if (type === 1) {
                oldArr = this.formData.extInfo.buttonBarConfig.buttonList;
            } else if (type === 2) {
                oldArr = this.formData.extInfo.tableRowButtonConfig.buttonList;
            }
            jo.forEach(oldArr, function (one) {
                if (one.code == dragBtn.code) {
                    // 自己不处理
                    return;
                }
                // 匹配到放置的按钮
                if (one.code == item.code) {
                    // 放置区按钮, 则放他后面or前面
                    if (position.atRight) {
                        arr.push(one);
                        arr.push(jo.copyObjectDeep(dragBtn));// 拷贝一份新对象, 支持跨按钮区域拖拽, 防止拖拽后修改发生联动
                    } else {
                        arr.push(jo.copyObjectDeep(dragBtn));
                        arr.push(one);
                    }
                } else {
                    arr.push(one);
                }
            });
            if (type === 1) {
                this.formData.extInfo.buttonBarConfig.buttonList = arr;
            } else if (type === 2) {
                this.formData.extInfo.tableRowButtonConfig.buttonList = arr;
            }
        },


        dragStart2(e, item) {
            // 设置被拖拽按钮
            this.dragData = item;
        },
        dragEnd2(e, item) {
            // 清空数据
            this.dragData = null;
            // 清空
            $('.btn-bar-item-left').removeClass('btn-bar-item-left');
            $('.btn-bar-item-right').removeClass('btn-bar-item-right');
        },
        dragOver2(e, item) {
            e.preventDefault();
            this.dragOverCore(e, item, this.dragData, 'fieldJavaName');
        },
        drop2(e, item, type) {
            if (!this.dragData) {
                console.warn('[拖拽放置] 被拖拽数据查找失败');
                return;
            }
            if (!item) {
                return;
            }
            // 被拖拽按钮配置
            var dragItem = this.dragData;
            if (dragItem.fieldJavaName == item.fieldJavaName) {
                console.log('[拖拽放置] 被拖拽数据与放置数据疑似同一个,不做处理');
                return;
            }

            // 定位信息
            var position = jo.getPositionDetail(e, 'btn-bar-item')

            // 判断鼠标是否过了中线, 过了就放右边, 否则放左边
            var arr = [];
            var oldArr = [];
            if (type === 1) {
                oldArr = this.formData.extInfo.searchConditionList;
            }
            jo.forEach(oldArr, function (one) {
                if (one.fieldJavaName == dragItem.fieldJavaName) {
                    // 自己不处理
                    return;
                }
                // 匹配到放置的按钮
                if (one.fieldJavaName == item.fieldJavaName) {
                    // 放置区按钮, 则放他后面or前面
                    if (position.atRight) {
                        arr.push(one);
                        arr.push(jo.copyObjectDeep(dragItem));
                    } else {
                        arr.push(jo.copyObjectDeep(dragItem));
                        arr.push(one);
                    }
                } else {
                    arr.push(one);
                }
            });
            if (type === 1) {
                this.formData.extInfo.searchConditionList = arr;
            }
        },


        // 拖拽在目标对象上移动, e:事件, item:目标数据, dragItem: 被拖拽数据, idAttrName:用来判断数据是否相等的字段
        dragOverCore(e, item, dragItem, idAttrName) {
            if (!item || !dragItem) {
                console.info('[拖拽在目标对象上移动] 目标数据和拖拽数据无效', item, dragItem)
                return;
            }
            if (dragItem[idAttrName] != item[idAttrName]) {
                var pos = jo.getPositionDetail(e, 'btn-bar-item');
                if ($(pos.target).hasClass('btn-bar-item-left') && pos.atLeft) {
                    // 已经是左侧提示的并且目前还在左侧的, 不处理
                } else if ($(pos.target).hasClass('btn-bar-item-right') && pos.atRight) {
                    // 已经是右侧提示的并且目前还在右侧的, 不处理
                } else {
                    // 清空
                    $('.btn-bar-item-left').removeClass('btn-bar-item-left');
                    $('.btn-bar-item-right').removeClass('btn-bar-item-right');
                    // 然后重新设置
                    if (pos.atLeft) {
                        $(pos.target).addClass('btn-bar-item-left');
                    } else {
                        $(pos.target).addClass('btn-bar-item-right');
                    }
                }
            } else {
                // 清空
                $('.btn-bar-item-left').removeClass('btn-bar-item-left');
                $('.btn-bar-item-right').removeClass('btn-bar-item-right');
            }
        },

    }
    , watch: {
        // 选中组件发生变化时的监听
        formConfigActiveEle() {
            var ele = this.formConfigActiveEle;
            if (ele) {
                if (!ele.styleList) {
                    ele.styleList = [];
                }
                if (ele.styleList.length === 0) {
                    ele.styleList.push({});
                }
                if (!ele.attrList) {
                    ele.attrList = [];
                }
                if (ele.attrList.length === 0) {
                    ele.attrList.push({});
                }
            }
        }
    }
    , mounted() {
        this.init();
    }
    , setup() {

    }
}, VUE_LOW_CODE_FORM_CONFIG_V2));
app.use(ElementPlus, {locale: ElementPlusLocaleZhCn});
joEl.component(app);

var appVM = app.mount("#app");


//大写格式转驼峰,首字母小写
function up2Tuo(str) {
    if (jo.isValid(str)) {
        var arr = str.split("_");
        if (arr.length > 1) {
            var s = arr[0].toLowerCase();
            for (var i = 1; i < arr.length; i++) {
                s += arr[i].substring(0, 1).toUpperCase() + arr[i].substring(1).toLowerCase();
            }
            return s;
        } else {
            return str.toLowerCase();
        }
    } else {
        return "";
    }
}

//单词首字母大写
function wordOne2Up(str) {
    return str.substring(0, 1).toUpperCase() + str.substring(1);
}

//单词首字母小写
function wordOne2Low(str) {
    return str.substring(0, 1).toLowerCase() + str.substring(1);
}

// 拖拽表单项开始
function moveColumnStart(col) {
    // 当前拖拽对象
    var target = event.target;
}

// 拖拽表单项过程中
function moveColumnIng() {
    moveCol(event);
}

// 拖拽表单项结束
function moveColumnEnd() {
    // 清空位置提示
    $('.preview-col-item').removeClass('move-col-before');
    $('.preview-col-item').removeClass('move-col-after');
    moveCol(event, function (target, item, type) {
        appVM.dragPosition(target, item, type);
        // 清空位置提示
        $('.preview-col-item').removeClass('move-col-before');
        $('.preview-col-item').removeClass('move-col-after');
    });
}

function moveCol(event, endFunc) {
    // 获取鼠标位置(窗口绝对位置)
    var x = event.pageX;
    var y = event.pageY;

    // 无效数据过滤
    if (!x || !y) {
        jo.log('鼠标坐标无效', [x, y, event]);
        return;
    }

    // 校准鼠标位置, 加上滚动条高度就是内容位置
    var scrollTop = $('.previewBoxScroll')[0].scrollTop;
    var scrollLeft = $('.previewBoxScroll')[0].scrollLeft;
    if (scrollTop) {
        y += scrollTop;
    }
    if (scrollLeft) {
        x += scrollLeft;
    }

    // 当前拖拽对象
    var target = event.target;

    // 计算每个表单项的位置
    var left = 320;// 父容器左侧距离
    var top = 70;// 父容器顶部距离
    // 所有的表单项
    var colArr = $('.preview-col-item');
    // 为每个表单项范围
    var rangeArr = [];
    jo.forEach(colArr, function (item, idx) {
        // 获取宽高, 计算中心点
        var width = item.clientWidth;
        var height = item.clientHeight;
        var absX = item.offsetLeft + left;
        var absY = item.offsetTop + top;
        // 表单项区域范围, 左上角点的xy坐标和右下角点的xy坐标
        rangeArr.push([absX, absY, absX + width, absY + height]);
    });

    console.info(rangeArr);

    for (var i = 0; i < colArr.length; i++) {
        var item = colArr[i];
        var range = rangeArr[i];
        var x1 = range[0];
        var y1 = range[1];
        var x2 = range[2];
        var y2 = range[3];
        // 判断鼠标是否在当前表单项范围内
        if (x > x1 && x < x2 && y > y1 && y < y2 && target != item) {
            // 先清空位置提示
            $('.preview-col-item').removeClass('move-col-before');
            $('.preview-col-item').removeClass('move-col-after');
            // 判断鼠标在中线左边还是右边
            var centerLineX = (x1 + x2) / 2;
            if (x > centerLineX) {
                if (typeof endFunc == 'function') {
                    endFunc(target, item, 'after');
                } else {
                    $(item).addClass('move-col-after');
                }
            } else {
                if (typeof endFunc == 'function') {
                    endFunc(target, item, 'before');
                } else {
                    $(item).addClass('move-col-before');
                }
            }
        }
    }
}

